package com.uphone.kingmall.view.indicator;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.china.zhuoyue.R;


/**
 * @作者 radish
 * @创建日期 2019/1/17 2:57 PM
 * @邮箱 15703379121@163.com
 * @描述 默认的ViewPager适配器
 */
public class IndicatorAdapter0 extends BaseIndicatorAdapter {

    private int msgCount = 0;
    protected String[] mItems0;
    protected Context mContext;

    public IndicatorAdapter0(Context context, String[] titles0, int count) {
        this.mItems0 = titles0;
        this.mContext = context;
        this.msgCount = count;
    }

    @Override
    public int getCount() {
        return mItems0 == null ? 0 : mItems0.length;
    }

    @Override
    public View getView(int position, ViewGroup parent) {
        View view = View.inflate(mContext, R.layout.kingmall_layout_indicator, null);
        TextView tv_tab = view.findViewById(R.id.tv_tab);
        tv_tab.setText(mItems0[position]);
        TextView tvTag = view.findViewById(R.id.tv_tag);
        if (position == 0 && msgCount > 0) {
            tvTag.setVisibility(View.VISIBLE);
            tvTag.setText(msgCount + "");
        } else {
            tvTag.setVisibility(View.GONE);
        }
        return view;
    }


    @Override
    public void highLightIndicator(View view, int position) {
        TextView tv_tab = view.findViewById(R.id.tv_tab);
        tv_tab.setTextColor(getChangeTextColor());
        tv_tab.setTextSize(getChangeTextSize());
        view.setSelected(true);
    }

    @Override
    public void restoreIndicator(View view, int position) {
        TextView tv_tab = view.findViewById(R.id.tv_tab);
        tv_tab.setTextColor(getOriginTextColor());
        tv_tab.setTextSize(getOriginTextSize());
        view.setSelected(true);

    }

    @Override
    public View getBottomTrackView() {
        View view = new View(mContext);
        view.setBackgroundColor(getChangeTextColor());
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 8);
        view.setLayoutParams(params);
        return view;
    }
}
